package com.itheima.controller;

import com.itheima.pojo.Product;
import com.itheima.pojo.ProductPageVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.ArrayList;
import java.util.List;

@Controller
public class ProductController {

    /**
     * 获取商品列表(使用List绑定数据)
     */
    @RequestMapping("/getProducts")
    public String getProducts(@RequestParam("proIds") List<String> proIds, Model model) {
        for (String proId : proIds) {
            System.out.println("获取到了Id为" + proId + "的商品");

        }
        model.addAttribute("proIds", proIds);
        return "output";
    }

    @RequestMapping("/getProducts1")
    public String getProducts1(ProductPageVO productListVO, Model model) {
        List<Product> productList = new ArrayList<>();
        for (Product product : productListVO.getProductList()) {
            if (product.getProId() != null) {
                productList.add(product);
                System.out.println("获取到了" + product + "的商品");
            }
        }
        model.addAttribute("proIds", productList);
        return "output";
    }
}

